package com.youshuit.designmodedemo.factory;

import com.youshuit.designmodedemo.enumx.PayType;
import com.youshuit.designmodedemo.service.IPaymentService;
import com.youshuit.designmodedemo.service.impl.factory.AlipayPaymentServiceImpl;
import com.youshuit.designmodedemo.service.impl.factory.CmbPaymentServiceImpl;
import com.youshuit.designmodedemo.service.impl.factory.WechatPaymentServiceImpl;

public class PaymentFactory {

    public static IPaymentService creatPayment(String payTypeCode){
        PayType payType = PayType.getByCode(payTypeCode);
        if (payType == null) {
            throw new IllegalArgumentException("不支持的支付类型");
        }
        return createPayment(payType);
    }


    public static IPaymentService createPayment(PayType payType) {
        return switch (payType) {
            case WECHAT -> new WechatPaymentServiceImpl();
            case ALIPAY -> new AlipayPaymentServiceImpl();
            case CMB -> new CmbPaymentServiceImpl();
            default -> throw new IllegalArgumentException("不支持的支付类型");
        };
    }
}
